import axios from 'axios';
import { IFilmPageRes } from '@/types/Film';

/**
 * 获取卖座 正在上映电影
 * @param {number} pageNum
 * @param {number} pageSize
 * @param {number} type
 * @param {number} cityId
 * @returns
 */
const findFilmsPage = (
  pageNum = 1,
  pageSize = 10,
  type = 1,
  cityId = 420100
): Promise<IFilmPageRes> => {
  return new Promise((resolve, reject) => {
    axios({
      url: 'https://m.maizuo.com/gateway',
      method: 'get',
      params: {
        cityId: cityId,
        pageNum: pageNum,
        pageSize: pageSize,
        type: type,
        k: 3287557,
      },
      headers: {
        'X-Client-Info':
          '{"a":"3000","ch":"1002","v":"5.2.1","e":"1696121400644206439694337","bc":"110100"}',
        'X-Host': 'mall.film-ticket.film.list',
      },
    })
      .then((res) => {
        return resolve(res.data.data);
      })
      .catch((err) => {
        console.log(err);
        reject(err);
      });
  });
};

/**
 * 获取电影院
 * @param {number} cityId
 * @param {number} ticketFlag
 * @returns
 */
const findCinemas = (cityId = 110100, ticketFlag = 1) => {
  return new Promise((resolve, reject) => {
    axios({
      url: 'https://m.maizuo.com/gateway',
      method: 'get',
      params: {
        cityId: cityId,
        ticketFlag: ticketFlag,
        k: 1363121,
      },
      headers: {
        'X-Client-Info':
          '{"a":"3000","ch":"1002","v":"5.2.1","e":"1695884087838184342650881","bc":"110100"}',
        'X-Host': 'mall.film-ticket.cinema.list',
      },
    })
      .then((res) => {
        return resolve(res.data.data);
      })
      .catch((err) => {
        console.log(err);
        reject(err);
      });
  });
};

/**
 * 获取城市
 * @returns
 */
const findCities = () => {
  return new Promise((resolve, reject) => {
    axios({
      url: 'https://m.maizuo.com/gateway',
      method: 'get',
      params: {
        k: 6575940,
      },
      headers: {
        'X-Client-Info':
          '{"a":"3000","ch":"1002","v":"5.2.1","e":"1695884087838184342650881"}',
        'X-Host': 'mall.film-ticket.city.list',
      },
    })
      .then((res) => {
        return resolve(res.data.data);
      })
      .catch((err) => {
        console.log(err);
        reject(err);
      });
  });
};

export { findFilmsPage, findCinemas, findCities };
